package com.pipline2;

import java.util.List;

/**
 * @author ycd0075
 * @date 2023-07-11 11:06
 */
public abstract class AbstractPipeline<T> implements Pipeline<T> {


    private final String name;

    /**
     * 当前流程执行完后下一个流程
     */
    private Pipeline<? super T> next;

    public AbstractPipeline(String name) {
        this.name = name;
    }

    public void setNext(Pipeline<? super T> next) {
        this.next = next;
    }

    @Override
    public abstract void process(PipelineContext ctx, T t);

    @Override
    public final void forward(PipelineContext ctx, T t) {
        if (next != null) {
            next.process(ctx, t);
        }
    }

    @Override
    public String toString() {
        if (next != null) {
            return name + "->" + next.toString();
        }
        return name;
    }

}
